import {Message} from 'element-ui';
import moment from 'moment';

class Tools {

    // 提示
    tooltip(obj) {
        let {
            type = 'error',
            message = '请传入提示语',
            duration = 2000,
            showClose = false,
            center = true,
            onClose = () => {return false}
        } = obj;
        Message({
            type,
            message,
            duration,
            showClose,
            center,
            customClass: 'tooltip',
            onClose
        });
    }
    // 存储
    storage(type = 'session', name = '', data = {}){
        if (!name)
            return;
        let storageData = JSON.stringify(data);
        type === 'session'
            ? window.sessionStorage.setItem(name, storageData)
            : window.localStorage.setItem(name, storageData);
    }
    // 获取存储
    getStorage(type = 'session', name = ''){
        if (!name)
            return;
        let data = type === 'session' ? window.sessionStorage.getItem(name) : window.localStorage.getItem(name);
        if (!data || !Object.keys(data))
            return null
        return JSON.parse(data);
    }
    // 路由跳转
    routerPath(path) {
        if (!path)
            return false;
        this.$router.push(path);
    }
    // 时间格式化
    formatTime(value, format = 'YYYY-MM-DD HH:mm:ss') {
        return moment(value).format(format);
    }
    //
}

export default new Tools();